#include <iostream>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <string.h>
#include <errno.h>

using namespace std;
enum {
};
const int PORT = 10241;
class CHttpSocket {
	public:
		CHttpSocket(int port = PORT);
		~CHttpSocket();
		void start();
	private:
		//private data members
		int mSockFd;
		int mPort;
		struct sockaddr_in mServAddr;
		//private functions
		void init();
};
CHttpSocket::CHttpSocket(int port):
	mPort(port)
{
	cout<<port<<endl;
}
CHttpSocket::~CHttpSocket()
{
	close(mSockFd);
}
void CHttpSocket::init()
{

	int res;
	mSockFd = socket(AF_INET, SOCK_STREAM, 0);
	if(mSockFd <= 0)
		cout<<"failed to socket!"<<endl;
	bzero(&mServAddr, sizeof(struct sockaddr_in));
	mServAddr.sin_port = ntohs(mPort);
	mServAddr.sin_addr.s_addr = 0;
	mServAddr.sin_family = AF_INET;
	res = bind(mSockFd, (struct sockaddr *) &mServAddr, sizeof(struct sockaddr));
	if(res != 0){
		cout<<"failed to bind()!"<<endl;
		cout<<strerror(errno)<<endl;
		return ;
	}
	res = listen(mSockFd, 0);
	if(res != 0){
		cout<<"failed to listen"<<endl;
		return;
	}
}
void CHttpSocket::start()
{
	init();
}
int main(int argc, char **argv)
{
	CHttpSocket server;
	server.start();

	return 0;
}
